<?php 
error_reporting(0);
/**
 * 
 * 配置 处理类
 * @author tanzhe
 *
 */
class config {
	private $db;
	public function __construct() {
		$this->db = new Data();
		die('导入请注释掉代码');
	}
	
	public function importClothes() { //导入衣服信息
		require_once "./Excel/reader.php";
		$xl_reader= new Spreadsheet_Excel_Reader();
		$xl_reader->setOutputEncoding('UTF-8');
		$xl_reader->read("./xls/clothes.xls");
		$data = $xl_reader->sheets[0]['cells'];
		if ( empty($data) ) {
			die('没有任何信息');
		}
		unset($data[1]);
		if ( count($data) == 0 ) {
			die('没有任何信息');
		}
		$sql_truncate = "truncate table clothes";
		$this->db->query($sql_truncate);
		foreach ( $data as $v ) {
			$insertData = array(
				'label'=>$v[1],
				'name'=>$v[2],
				'shop_type'=>$v[3],
				'shop_id'=>$v[4],
				'type'=>$v[5],
				'hotness_type'=>$v[6],
				'hotness'=>$v[7],
				'cost_type'=>$v[8],
				'price'=>$v[9],
			);
			$this->db->insertData('clothes', $insertData);
		}
		echo 'import clothes done!';
	}
	
	public function importWork() { //导入工作信息
		require_once "./Excel/reader.php";
		$xl_reader= new Spreadsheet_Excel_Reader();
		$xl_reader->setOutputEncoding('UTF-8');
		$xl_reader->read("./xls/work.xls");
		$data = $xl_reader->sheets[0]['cells'];
		if ( empty($data) ) {
			die('没有任何信息');
		}
		unset($data[1]);
		if ( count($data) == 0 ) {
			die('没有任何信息');
		}
		$sql_truncate = "truncate table work";
		$this->db->query($sql_truncate);
		foreach ( $data as $v ) {
			$insertData = array(
				'label'=>$v[1],
				'name'=>$v[2],
				'workplace'=>$v[3],
				'earn'=>$v[4],
				'work_hotness'=>$v[5],
				'use_energy'=>$v[6],
				'experience'=>$v[7],
			);
			$this->db->insertData('work', $insertData);
		}
		echo 'import work done!';
	}
	
	public function importBoyfriend() { //导入男朋友模板
		require_once "./Excel/reader.php";
		$xl_reader= new Spreadsheet_Excel_Reader();
		$xl_reader->setOutputEncoding('UTF-8');
		$xl_reader->read("./xls/boyfriend.xls");
		$data = $xl_reader->sheets[0]['cells'];
		if ( empty($data) ) {
			die('没有任何信息');
		}
		unset($data[1]);
		if ( count($data) == 0 ) {
			die('没有任何信息');
		}
		$sql_truncate = "truncate table boyfriend";
		$this->db->query($sql_truncate);
		foreach ( $data as $v ) {
			$insertData = array(
				'label'=>$v[1],
				'name'=>$v[2],
				'quality'=>$v[3],
				'job'=>$v[4],
				'style'=>$v[12],
				'color'=>$v[13],
				'skin'=>$v[14],
				'manliness'=>18,
			);
			//衣服信息
			$clothes = array(
				1=>$v[5],
				2=>$v[6],
				3=>$v[7],
				4=>$v[8],
				5=>$v[9],
				6=>$v[10],
				7=>$v[11],
			);
			foreach ( $clothes as $k=>$v ) {
				if ( empty($v) ) {
					unset($clothes[$k]);
				}
			}
			//奖励
			$bonus = array(
				'add_coin'=>$v[15],
				'add_hanger'=>$v[16],
				'reduce_cd'=>$v[17],
			);
			foreach ( $bonus as $k=>$v ) {
				if ( empty($v) ) {
					unset($bonus[$k]);
				}
			}
			$insertData['clothes'] = serialize($clothes);
			$insertData['bonus'] = serialize($bonus);
			$this->db->insertData('boyfriend', $insertData);
		}
		echo 'import boyfriend done!';
	}
	
	public function importAppearance() { //导入外形 美容项目
		require_once "./Excel/reader.php";
		$xl_reader= new Spreadsheet_Excel_Reader();
		$xl_reader->setOutputEncoding('UTF-8');
		$xl_reader->read("./xls/appearance.xls");
		$data = $xl_reader->sheets[0]['cells'];
		if ( empty($data) ) {
			die('没有任何信息');
		}
		unset($data[1]);
		if ( count($data) == 0 ) {
			die('没有任何信息');
		}
		$sql_truncate = "truncate table appearance";
		$this->db->query($sql_truncate);
		foreach ( $data as $v ) {
			$insertData = array(
				'label'=>$v[1],
				'name'=>$v[2],
				'shop_id'=>$v[3],
				'type'=>$v[4],
				'sex'=>$v[5],
				'cost_type'=>$v[6],
				'price'=>$v[7],
				'rank'=>$v[8],
			);
			$this->db->insertData('appearance', $insertData);
		}
		echo 'import appearance done!';
	}
	
	public function importItem() { //导入道具
		require_once "./Excel/reader.php";
		$xl_reader= new Spreadsheet_Excel_Reader();
		$xl_reader->setOutputEncoding('UTF-8');
		$xl_reader->read("./xls/item.xls");
		$data = $xl_reader->sheets[0]['cells'];
		if ( empty($data) ) {
			die('没有任何信息');
		}
		unset($data[1]);
		if ( count($data) == 0 ) {
			die('没有任何信息');
		}
		$sql_truncate = "truncate table item";
		$this->db->query($sql_truncate);
		foreach ( $data as $v ) {
			$insertData = array(
				'label'=>$v[1],
				'shop_id'=>$v[2],
				'type'=>$v[3],
				'bonus'=>$v[4],
				'cost_type'=>$v[8],
				'price'=>$v[9],
				'stack'=>$v[10],
				'last_time'=>$v[11],
				'name'=>$v[12],
				'intro'=>$v[13],
				'rank'=>$v[14],
			);
			if ( $v[3] == 5 ) {
				//奖励
				$bonus = array(
					'add_coin'=>$v[5],
					'add_hanger'=>$v[6],
					'reduce_cd'=>$v[7],
				);
				foreach ( $bonus as $k=>$v ) {
					if ( empty($v) ) {
						unset($bonus[$k]);
					}
				}
				$insertData['bonus'] = serialize($bonus);
			}
			$this->db->insertData('item', $insertData);
		}
		echo 'import item done!';
	}
}
?>